package com.zhouxiaoge.socket.serversocket;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/***************************************************
 *                    _ooOoo_                  *   
 *                   o8888888o                 * 佛        
 *                  88'' . ''88                * 祖 
 *                  ( | -_- | )                * 保 
 *                   0\  =  /0                 * 佑 
 *                ____/'---'\____              *    
 *              .'  \\|     |//  '.            * 永 
 *             /  \\|||  :  |||//  \           * 无 
 *            /  _||||| -:- |||||-  \          * BUG
 *            |   | \\\  -  /// |   |          *
 *            | \_|  ''\---/''  |   |          * 阿
 *            \  .-\__  `-`  ___/-. /          * 弥
 *          ___`. .'  /--.--\  `. . __         * 陀
 *       ."" '<  ‘.___\_<|>_/___.’  >'"".      * 佛
 *      | | :  ` - `.;`\ _ /`;.`/ - ` : | |    *
 *      \  \ `-.   \_ __\ /__ _/   .-` /  /    * 
 * ======`-.____`-.___\_____/___.-`____.-'=====*
 * @author 周明阳 mail:gqzmy@outlook.com 时间:2017-12-11 9:22
 */
public class SocketServiceLoader implements ServletContextListener {
    //socket server 线程
    private SocketThread socketThread;

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        if (null != socketThread && !socketThread.isInterrupted()) {
            socketThread.closeSocketServer();
            socketThread.interrupt();
        }
    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        if (null == socketThread) {
            //新建线程类
            socketThread = new SocketThread(null);
            //启动线程
            socketThread.start();
        }
    }
}
